<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>食品增加</title>
<link rel="stylesheet" href="<%=basePath%>res/wzw/layui/css/layui.css"
	media="all">
<style type="text/css">
#goodsImg {
	position: relative;
	left: 110px;
}
</style>
</head>
<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>食品增加列表</legend>
	</fieldset>

	<form class="layui-form" action="<%=basePath%>food/foodAdd"
		method="post" id="myform">
		<input type="hidden" id="foodId" name="food_id">
		<div class="layui-form-item">
			<label class="layui-form-label">店家ID</label>
			<div class="layui-input-block">
				<input type="text" name="merchant_id" id="merchantId"
					   lay-verify="required" placeholder="请输入" autocomplete="off"
					   class="layui-input" maxlength="20">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">店家名称</label>
			<div class="layui-input-block">
				<input type="text" name="merchant_name" id="merchantName"
					   lay-verify="required" placeholder="请输入" autocomplete="off"
					   class="layui-input" maxlength="20">
			</div>
		</div>

<%--		<input type="hidden" name="type_id" id="typeId">--%>

		<div class="layui-form-item">
			<label class="layui-form-label">类型名称</label>
			<div class="layui-input-block">
				<select name="type_id" id="typeId" lay-verify="required"
					autocomplete="off" class="layui-input">
					<option></option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">食物名称</label>
			<div class="layui-input-block">
				<input type="text" name="food_name" id="foodName"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="20">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">食物价格</label>
			<div class="layui-input-block">
				<input type="number" name="food_price" id="foodPrice"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="10">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">食物月售</label>
			<div class="layui-input-block">
				<input type="number" name="food_sell" id="foodSell"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="10">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">是否有效</label>
			<div class="layui-input-block">
				<select name="isva" id="isva" required lay-verify="required"
					autocomplete="off" class="layui-input">
					<option></option>
					<option value="0">无效</option>
					<option value="1">有效</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<div class="layui-upload">
					<label class="layui-form-label">上传图片</label>
					<button type="button" class="layui-btn" id="test1">上传图片</button>
					<div class="layui-upload-list" style="margin:10px 54%;">
						<img class="layui-upload-img" id="demo1" width="90px" height="90px">
						<p id="demoText" style="width:120px;margin:10px 0px;"></p>
						<input type="hidden" id="picSite" name="pic_site">
					</div>
				</div>
			</div>
		</div>
		<!-- 提交重置 -->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input  type="submit" class="layui-btn" lay-submit=""
					lay-filter="foodAdd" value="立即提交">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<script src="<%=basePath%>res/wzw/layui/layui.js"></script>
	<script type="text/javascript" src="res/wzw/js/jquery.min.1.6.4.js"></script>
	<script src="<%=basePath%>js/jquery-1.10.2.js"></script>

	<script>
	layui.use(['form', 'layer','upload'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,upload=layui.upload
	  ,$ = layui.$;
	  
	  form.on('submit(foodAdd)',function(){
		  parent.location.reload(); // 父页面刷新
	  });
		//查询类型
		var url = "<%=basePath%>foodType/findAllType";
		//var data = {limit:"10",page:"1"};
		$.post(url,null,function(data){
			data = data.data;
			for(var i=0;i<data.length;i++){
				$("#typeId").append("<option  value="+data[i].type_id+">"+data[i].type_name+"</option>");
			}
			//form表单重新渲染
			form.render();
		},dataType="JSON");
		// form.render('select');
		// form.render('select','selFilter');
		
		//普通图片上传
	upload.render({
		elem: '#test1'
		,url: '<%=basePath %>upload/uploadFile'
		,before: function(obj){
			//预读本地文件示例，不支持ie8
			obj.preview(function(index, file, result){
				$('#demo1').attr('src', result); //图片链接（base64）
			});
		}
		,done: function(res){
			//如果上传失败
			if(res.code > 0){
				return layer.msg('上传失败');
			}
			//上传成功
			$("#picSite").val(res.msg);
		}
		,error: function(){
			//演示失败状态，并实现重传
			var demoText = $('#demoText');
			demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
			demoText.find('.demo-reload').on('click', function(){
				uploadInst.upload();
			});
		}
	});
	});
</script>

</body>
</html>